package com.touna.controller;

import com.alibaba.fastjson.JSONObject;
import com.touna.bean.VoiceRecord;
import com.touna.com.touna.service.VoiceService;
import com.touna.domain.Response;
import com.touna.tools.CommonUtil;
import com.touna.tools.JSONUtils;
import com.touna.tools.Page;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

@Controller
public class ZixinController {


    @RequestMapping(value = "/report/gateway", method = {RequestMethod.POST})
     @ResponseBody
    public JSONObject handleRequest(HttpServletRequest request, HttpServletResponse response) {
        try {
            String paramsString= CommonUtil.getParams(request);
            String  method= JSONUtils.getString(paramsString,"method",null);
            JSONObject params= JSONUtils.getJSONObject(paramsString,"params",null);
            String authItem =  params.getString("authItem");
            System.out.println(method);
            if("datareport.gongxinbao.data".equals(method) && authItem.equals("wechat")){
                JSONObject response1 = new JSONObject();
                String content = FileUtils.readFileToString(new File("E:\\work\\zixin_refactor\\zhilian_report\\weixin_auth.txt"),"UTF-8");
                response1.put("data",JSONObject.parse(content));
                response1.put("code","200");
                return response1;
            }
            else if("datareport.gongxinbao.data".equals(method) && authItem.equals("ecommerce")){
                JSONObject response1 = new JSONObject();
                String content = FileUtils.readFileToString(new File("E:\\work\\zixin_refactor\\zhilian_report\\zfb_auth.txt"),"UTF-8");
                response1.put("data",JSONObject.parse(content));
                response1.put("code","200");
                return response1;
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }



}